package com.everflourish.yeah100.utils.collections;

import com.everflourish.yeah100.entity.marking.Topic;

import java.util.Comparator;

/**
 * 题型设置排序（根据开始题号排序）
 *
 * @author pf
 * @date 2015-3-16
 */
public class TopicCollections implements Comparator<Topic> {

    // 是否是降序排序
    private boolean isDesc = false;

    public TopicCollections(boolean isDesc) {
        this.isDesc = isDesc;
    }

    @Override
    public int compare(Topic lhsTopic, Topic rhsTopic) {
        int compareFlag = 0;
        Integer lhsTopicBegin = lhsTopic.getTopicBegin();
        Integer rhsTopicBegin = rhsTopic.getTopicBegin();
        if (lhsTopicBegin == null) {
            lhsTopicBegin = -1;
        }
        if (rhsTopicBegin == null) {
            rhsTopicBegin = -1;
        }
        compareFlag = lhsTopicBegin - rhsTopicBegin;
        if (isDesc) {
            compareFlag = -compareFlag;
        }
        return compareFlag;
    }
}
